﻿using System.Collections.Generic;
using System.Linq;
using System.Web.Http;
using IceDog.DNF.Program.WebApi2.Models;

namespace IceDog.DNF.Program.WebApi2.Controllers
{
    //[RoutePrefix("")]
    public class AppleController : ApiController
    {
        List<Apple> _list = new List<Apple>
        {
            new Apple{Id = 1,From = "China"},
            new Apple{Id = 2,From = "China"},
            new Apple{Id = 3,From = "China"},
            new Apple{Id = 4,From = "China"},
            new Apple{Id = 5,From = "Japan"},
        };
        public IEnumerable<Apple> GetAll()
        {
            return _list;
        }

        public Apple GetAppleById(int id)
        {
            return _list.First(a => a.Id.Equals(id));
        }
        [HttpGet,Route("api/apple/{name}/info")]
        public string GetDefaultName(string name)
        {
            return name;
        }

        [HttpGet]
        public Apple FindAppleByFrom(string from)
        {
            return _list.First(a => a.From.Equals(from));
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="from"></param>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpGet]
        public Apple FindAppleByFrom(string from,int id)
        {
            return _list.First(a => a.From.Equals(from)&&a.Id.Equals(id));
        }
        public void Post(Apple value)
        {
            
        }

        public void Put(int id, Apple value)
        {
            
        }
    }
}
